package com.telsoft.hms.data;

import com.telsoft.hms.lib.admin.client.data.ClientDataPreprocessor;

public class HMS_News_DATA  extends ClientDataPreprocessor{

	public HMS_News_DATA () {
		super();
	}
	/**
	 * Xóa tin tức
	 * @author ToiVT
	 * @param strSecurityKey
	 *            Mã bảo mật
	 * @param lId
	 *            id tin tức
	 * @param languageCode
	 *            Mã ngôn ngữ
	 * @throws Exception
	 * Ngày tạo: 08/10/2014
	 */
	@SuppressWarnings("finally")
	public boolean deleteNews (String strHospitalKey, long lNewsId, int iLanguageCode) throws Exception{
		boolean flag = true;
		try {
			open(strHospitalKey);
			mConnection.setAutoCommit(false);
			String strSql = "DELETE FROM NEWS_VALUES WHERE NEWS_ID=? and LANGUAGE_CODE=?";
			String strSql2 = "DELETE FROM NEWS_REF WHERE NEWS_ID NOT IN (SELECT NEWS_ID FROM NEWS_VALUES)";
			
			// Xóa tin tức (theo language_code)
			mStmt = mConnection.prepareStatement(strSql);
			mStmt.setLong(1, lNewsId);
			mStmt.setInt(2, iLanguageCode);
			mStmt.executeUpdate();
			mStmt.clearBatch();
			
			// Xóa NEWS_REF nếu xóa hết theo language_code
			mStmt = mConnection.prepareStatement(strSql2);
			mStmt.executeUpdate();
			mConnection.commit();
		} catch (Exception ex) {
			mConnection.rollback();
			flag = false;
			throw ex;
		} finally {
			close(mStmt, mConnection);
			return flag;
		}
		
	}
}
